function mySlice(num1?: number, num2?: number): void {
  console.log('起始索引：', num1, '结束索引：', num2)
}

mySlice()
mySlice(1)
mySlice(1, 2)

// 函数声明
function sumFunc(x: number, y: number): number {
  return x + y;
}

// 函数表达式
let sumFunc2: (x: number, y: number) => number = function (x: number, y: number): number {
  return x + y;
}

// 用接口定义函数的形状
interface ISumFunc {
  (x: number, y: number): number
}

let sumFunc3: ISumFunc = function (x: number, y: number): number {
  return x + y;
}

// 可选参数
// 可选参数必须跟在必选参数后边
function buildName(firstName: string, lastName?: string): string {
  if (lastName) {
    return firstName + ' ' + lastName;
  } else {
    return firstName;
  }
}

let tomcat = buildName('Tom', 'Cat');
let tomcat2 = buildName('Tom');

// 参数默认值（ts会把添加默认值的参数识别为可选参数，且不受[可选参数必须接在必须参数后边]的限制）
function buildName2(firstName: string, lastName: string = 'Cat'): string {
  return firstName + '' + lastName;
}
let tomcat3 = buildName2('Tom', 'Cat');
let tomcat4 = buildName2('Tom');

// 剩余参数
// rest参数只能是最后一个参数
function push(array: any[], ...items: any[]) {
  items.forEach(function (item) {
    array.push(item);
  });
}
let myArray: any[] = [];
push(myArray, 1, 2, 3);